<script type="text/javascript">
	$(document).ready(function(){
		$("#mensaje").hide();
		$("#imgCarga").hide();
		$("#baceptar").show();
		$("#baceptar").click(registrarUsuario);
	});
	function registrarPeli()
	{
		$.ajax({
  			type: "POST",
  			url: "modulos/usuarios/regusuaction.php",
  			data: {
  				titulo: $("#tit").val(),
  				titulovo: $("#titvo").val(),
  				idioma: $("#idi").val(),
  				anyo: $("#anyo").val(),
  				duracion: $("#dur").val(),
  				nacimiento: $("#nacimiento").val(),
  				arg: $("#sin").val(),
  				pais: $("#pais").val()
  			},
  			beforeSend: function(){
  				$("#mensaje").hide();
  				$("#imgCarga").show();
  				$("#baceptar").hide();
  			},
  			success: function(resp){
  				$("#imgCarga").hide();
  				$("#baceptar").hide();
  				if (resp == "ok")
  				{
  					$("#mensaje").html("La pelicula se ha dado de alta correctamente");
  				}else{
  					$("#mensaje").html(resp);
  				}
  				$("#baceptar").show();
  				$("#mensaje").show();
  			}
		});
	}
</script>

<form class="pure-form pure-form-stacked">
	<div style="float:left;">
	<label for="tit">Titulo:</label>
	<input type="text" id="tit" name="tit" maxlength="50">
	<label for="titvo">Titulo Original:</label>
	<input type="text" id="titvo" name="titvo" maxlength="50">
	<label for="idi">Idioma:</label>
	<input type="text" id="idi" name="idi" maxlength="20" onkeypress="return letras(event);">
	<label for="anyo">A&ntilde;o:</label>
	<select name="anyo" id="anyo">
		<?php
		for($anyo=(date("Y")); 1900<=$anyo; $anyo--) {
			echo "<option value='".$anyo."'>".$anyo."</option>";
		}
		?>
	</select>
	<label for="dur">Duraci&oacute;n:</label>
	<input type="text" id="dur" name="dur" maxlength="3" onkeypress="return numeros(event);">
	<label for="idi">Idioma:</label>
	<input type="text" id="idi" name="idi" maxlength="20" onkeypress="return letras(event);">
	<label for="pais">Pais:</label>
	<select name="pais" id="pais">
		<?php
	    $array_paises = array("Estados Unidos","Espa&ntilde;a","Republica Dominicana","Afganistan","Africa del Sur","Albania","Alemania","Andorra","Angola","Antigua y Barbuda","Antillas Holandesas","Arabia Saudita","Argelia","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarusia","Belgica","Belice","Benin","Bermudas","Bolivia","Bosnia","Botswana","Brasil","Brunei Darussulam","Bulgaria","Burkina Faso","Burundi","Butan","Camboya","Camerun","Canada","Cape Verde","Chad","Chile","China","Chipre","Colombia","Comoros","Congo","Corea del Norte","Corea del Sur","Costa de Marf&iacute;l","Costa Rica","Croasia","Cuba","Dinamarca","Djibouti","Dominica","Ecuador","Egipto","El Salvador","Emiratos Arabes Unidos","Eritrea","Eslovenia","Estonia","Etiopia","Fiji","Filipinas","Finlandia","Francia","Gabon","Gambia","Georgia","Ghana","Granada","Grecia","Groenlandia","Guadalupe","Guam","Guatemala","Guayana Francesa","Guerney","Guinea","Guinea-Bissau","Guinea Equatorial","Guyana","Haiti","Holanda","Honduras","Hong Kong","Hungria","India","Indonesia","Irak","Iran","Irlanda","Islandia","Islas Caiman","Islas Faroe","Islas Malvinas","Islas Marshall","Islas Solomon","Islas Virgenes Britanicas","Islas Virgenes (U.S.)","Israel","Italia","Jamaica","Japon","Jersey","Jordania","Kazakhstan","Kenia","Kiribati","Kuwait","Kyrgyzstan","Laos","Latvia","Lesotho","Libano","Liberia","Libia","Liechtenstein","Lituania","Luxemburgo","Macao","Macedonia","Madagascar","Malasia","Malawi","Maldivas","Mali","Malta","Marruecos","Martinica","Mauricio","Mauritania","Mexico","Micronesia","Moldova","Monaco","Mongolia","Mozambique","Myanmar (Burma)","Namibia","Nepal","Nicaragua","Niger","Nigeria","Noruega","Nueva Caledonia","Nueva Zealandia","Oman","Pakistan","Palestina","Panama","Papua Nueva Guinea","Paraguay","Peru","Polinesia Francesa","Polonia","Portugal","Puerto Rico","Qatar","Reino Unido","Republica Centroafricana","Republica Checa","Republica Democratica del Congo","Republica Eslovaca","Reunion","Ruanda","Rumania","Rusia","Sahara","Samoa","San Cristobal-Nevis (St. Kitts)","San Marino","San Vincente y las Granadinas","Santa Helena","Santa Lucia","Santa Sede (Vaticano)","Sao Tome & Principe","Senegal","Seychelles","Sierra Leona","Singapur","Siria","Somalia","Sri Lanka (Ceilan)","Sudan","Suecia","Suiza","Sur Africa","Surinam","Swaziland","Tailandia","Taiwan","Tajikistan","Tanzania","Timor Oriental","Togo","Tokelau","Tonga","Trinidad & Tobago","Tunisia","Turkmenistan","Turquia","Ucrania","Uganda","Union Europea","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Yemen","Yugoslavia","Zambia","Zimbabwe");
    	$cantidad_paises = count($array_paises);
    	for($i = 0; $i<$cantidad_paises; $i++){
        	$array_paises_i = $array_paises[$i];
        	echo "<option value='".$array_paises_i."'>".$array_paises_i."</option>";
		}
		?>
	</select>
	<label for="sin">Argumento:</label>
	<textarea name="sin" id="sin" onkeypress="return letras(event);"></textarea>
	<label for="cartel">Cartel:</label>
	<input type="file" name="cartel" id="cartel">
	</div>
	<div style="float:right;">
	<label for="dir1">Director:</label>
	<input type="text" id="dir1" name="dir1" maxlength="20" onkeypress="return letras(event);">
	<div id="campdir"></div>
	<a href="#" onclick="AgregarDire();">Agregar Director</a>
	<label for="act1">Actor/Actriz:</label>
	<input type="text" id="act1" name="act1" maxlength="20" onkeypress="return letras(event);">
	<div id="campact"></div>
	<a href="#" onclick="AgregarAct();">Agregar Actor/Actriz</a>
 	</div>
 	<div class="limpia"></div>
 	<div style="text-align:center;">
 		<input type="submit" name="benviar" id="benviar" value="Agregar Pelicula" class="pure-button notice">
 	</div>
</form>
<script type="text/javascript">
	function numeros (e) {
		var keynum = window.event ? window.event.keyCode : e.which;
		if ((keynum == 8) || (keynum == 46)) {
			return true;
		}
		return /\d/.test(String.fromCharCode(keynum));
	}
	function letras (e) {
    	var tecla = (document.all) ? e.keyCode : e.which;
    	if (tecla==8) {
    		return true;
    	}
    	var patron =/[A-Za-z\s]/;
    	var te = String.fromCharCode(tecla);
    	return patron.test(te);
	}
	var limit=10;
	var nextdir = 1;
	var nextact = 1;
	function AgregarDire(){
		if ($("#dir"+nextdir).val()=="") {
			alert("Antes de agregar, rellene el campo director");
			return false;
		}
		if (nextdir!=limit) {
			nextdir++;
			var campo = '<label for="dir' + nextdir + '">Director ' + nextdir + ':</label><br><input type="text" maxlength="50" id="dir' + nextdir + '"  name="dir' + nextdir + '"  onkeypress="return letras(event);"><br>';
			$("#campdir").append(campo);
		}
		else {
			alert("Limite de directores alcanzado");
		}
	}
	function AgregarAct(){
		if ($("#act"+nextdir).val()=="") {
			alert("Antes de agregar un nuevo actor, rellene el campo Actor/Actriz");
			return false;
		}
		if (nextact!=limit) {
			nextact++;
			var campo = '<label for="act'+nextact+'">Actor/Actriz '+nextact+':</label><br><input type="text" maxlength="50" id="act' + nextact + '" name="act' + nextact + '"  onkeypress="return letras(event);"><br>';
			$("#campact").append(campo);
		}
		else {
			alert("Limite de actores alcanzado");
		}
	}
	/*function eliminad (elemento) {
		$('#' + elemento).remove();
		$("label[for='" + elemento + "']").remove();
		$("a[title='" + elemento + "']").remove();
		$("#campdir").html("");
		nextdir--;
	}*/
</script>